package com.sds.thesis.util;


import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.commons.io.FileUtils;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class t {
    @Test
    public void svgToImg() throws IOException, TranscoderException {
// 读取SVG文件
        File svgFile = new File("E:\\code\\java\\springboot-learn-hub\\springboot-file\\springboot-file-word\\springboot-file-word-poi-tl\\src\\main\\resources\\thesis\\sys_module.svg");
        String svgContent = FileUtils.readFileToString(svgFile, "UTF-8");

        // 创建TranscoderInput对象
        TranscoderInput input = new TranscoderInput(new StringReader(svgContent));

        // 创建TranscoderOutput对象
        File pngFile = new File("D:/file.png");
        OutputStream outputStream = new FileOutputStream(pngFile);
        TranscoderOutput output = new TranscoderOutput(outputStream);

        // 创建PNGTranscoder对象并转换SVG到PNG
        PNGTranscoder transcoder = new PNGTranscoder();
        transcoder.transcode(input, output);

        // 关闭输出流
        outputStream.close();
    }

}
